package com.kotodama.infrastructure.tenant.resolver;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.util.StringUtils;

/**
 * 从子域名解析租户ID，例如 tenant1.example.com -> tenant1
 */
public class SubdomainTenantResolver implements TenantResolver {
    @Override
    public String resolveTenantId(HttpServletRequest request) {
        String host = request.getServerName();
        if (!StringUtils.hasText(host) || !host.contains(".")) {
            return null;
        }
        return host.split("\\.")[0];
    }
}
